package gameLogic

import (
	"strings"

	lua "github.com/yuin/gopher-lua"
)

//游戏逻辑的具体分发&处理
//客户端上来的是raw telnet 指令，需要在这里按照空格解析
var onDefaultRes string = "nothing happend"

func GameLogicEntry(infoMap *map[string]string, reqBuffer []byte, vm *lua.LState) []byte {
	params := Bytes2str(reqBuffer)
	params = strings.Replace(params, "\n", "", -1)
	params = strings.Replace(params, "\r", "", -1)
	paramsVec := strings.Split(params, " ")
	switch paramsVec[0] {
	case "login":
		{
			return GameLogin(infoMap, paramsVec[1:])
		}
	case "reg":
		{
			return GameRegister(infoMap, paramsVec[1:])
		}
	default:
		{
			//连接的登录态校验
			if !IsUserLogin(infoMap) {
				return Str2bytes("you has no login, please login first!")
			}
			return GameExec(infoMap, paramsVec, vm)
		}
	}
	return Str2bytes(onDefaultRes)
}
